<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use app\model\not_del\UserModel as NotDelUserModel;
use app\model\not_del\RatingScaleModel as NotDelRatingScaleModel;

/**
 * 心理咨询-线上测评结果
 */
class ConsultOnlineResultModel extends BaseModel
{
    protected $name = 'consult_online_result';

    /**
     * 关联用户名称
     * @return BelongsTo
     */
    public function UserName(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
        ]);
    }

    /**
     * 关联用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'username',
            'role_mode',
            'phone',
            'student_status',
            'user_name' => 'name',
            'age',
            'sex',
            'department_id',
            'department_name',
            'unit_name',
            'role_name',
        ]);
    }

    /**
     * 关联量表
     * @return BelongsTo
     */
    public function ratingScale(): BelongsTo
    {
        return $this->belongsTo(NotDelRatingScaleModel::class,'rating_scale_id')->bind([
            'rating_scale_name' => 'name',
            'rating_scale_type_id' => 'type_id',
            'rating_scale_introduce' => 'introduce',
            'rating_scale_notice' => 'notice',
            'rating_scale_type_name',
            'rating_scale_cover' => 'cover',
            'previous_name',
            'mode_name'
        ]);
    }

    /**
     * 关联因子预警
     * @return BelongsTo
     */
    public function RatingScaleFactorWarningModel(): BelongsTo
    {
        return $this->belongsTo('RatingScaleFactorWarningModel','warning_id')->bind([
            'warning_name' => 'name',
            'mark_id',
            'mark_count',
            'mark_color_id',
            'factor_name'
        ]);
    }

    /**
     * 关联测评结果因子
     * @return HasMany
     */
    public function ConsultOnlineFactorScore(): HasMany
    {
        return $this->hasMany('ConsultOnlineFactorScoreModel','result_id');
    }


}